﻿using System;
using System.Windows.Forms;

namespace OFFICE_Helper.Forms
{
    public partial class WaitForm : Form
    {
        private EventHandler<EventArgs> _Method;
        private IAsyncResult asyncResult;
        private delegate void WaitTextDelegate(string text);
        public WaitForm(EventHandler<EventArgs> Method)
        {
            InitializeComponent();
            _Method = Method;
        }
        private void WaitForm_Shown(object sender, EventArgs e)
        {
            asyncResult = _Method.BeginInvoke(this, null, null, null);
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (asyncResult.IsCompleted)
            {
                this.Close();
            }
        }
        public void SetText(string text)
        {
            if (this.InvokeRequired)
            {
                WaitTextDelegate del = new WaitTextDelegate(SetText);
                this.Invoke(del, new object[] { text });
            }
            else
            {
                lb.Text = text;
            }
        }
    }
}
